/**
 * \file Color.cpp
 *	\brief Color declaration class
 * \author Edouard ROGE
 * \date 12 august 2012
 */

#include "Color.h"

Color::Color()
{
	m_Value=0;
}

Color::Color(uint32 _color)
{
	m_Value=_color;
}

Color::Color(const Color & _color)
{
	m_Value=_color.m_Value;
}

Color::Color(float _red, float _green, float _blue, float _alpha)
{
	SetRedComponent(_red);
	SetGreenComponent(_green);
	SetBlueComponent(_blue);
	SetAlphaComponent(_alpha);
}

Color::Color(uint8 _red, uint8 _green, uint8 _blue, uint8 _alpha)
{
	SetRedComponent(_red);
	SetGreenComponent(_green);
	SetBlueComponent(_blue);
	SetAlphaComponent(_alpha);
}

Color::~Color()
{
}

uint8 Color::GetRedComponent() const
{
	return (uint8)(m_Value&0xFF000000);
}

uint8 Color::GetGreenComponent() const
{
	return (uint8)(m_Value&0x00FF0000)<<8;
}

uint8 Color::GetBlueComponent() const
{
	return (uint8)(m_Value&0x0000FF00)<<16;
}

uint8 Color::GetAlphaComponent() const
{
	return (uint8)(m_Value&0x00000FF)<<24;
}

void Color::SetRedComponent(uint8 _red)
{
	m_Value=(m_Value&0x00FFFFFF)+_red;
}

void Color::SetGreenComponent(uint8 _green)
{
	m_Value=(m_Value&0xFF00FFFF)+(_green>>8);
}

void Color::SetBlueComponent(uint8 _blue)
{
	m_Value=(m_Value&0xFFFF00FF)+(_blue>>16);
}

void Color::SetAlphaComponent(uint8 _alpha)
{
	m_Value=(m_Value&0xFFFFFF00)+(_alpha>>24);
}

void Color::SetRedComponent(float _red)
{
	_red=(_red<0.f?0:(_red>1.0f?1.0f:_red));
	SetRedComponent((uint8)(_red*255));
}

void Color::SetGreenComponent(float _green)
{
	_green=(_green<0.f?0:(_green>1.0f?1.0f:_green));
	SetGreenComponent((uint8)(_green*255));
}

void Color::SetBlueComponent(float _blue)
{
	_blue=(_blue<0.f?0:(_blue>1.0f?1.0f:_blue));
	SetBlueComponent((uint8)(_blue*255));
}

void Color::SetAlphaComponent(float _alpha)
{
	_alpha=(_alpha<0.f?0:(_alpha>1.0f?1.0f:_alpha));
	SetAlphaComponent((uint8)(_alpha*255));
}

Color::operator const uint32 & () const
{
	return m_Value;
}

Color::operator uint32 & ()
{
	return m_Value;
}
